package zqkcom.atguigu.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class LoginFilter extends HttpFilter {


    @Override
    public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpSession session = request.getSession();

        Object user = session.getAttribute("user");

        if (user == null) {
            //没有
            request.setAttribute("errorMsg", "请先实现订单功能");
            request.getRequestDispatcher("/pages/user/login.jsp").forward(request, response);

        } else {
            chain.doFilter(request,response);
        }
    }
}
